<?php
	/*
	*数据库操作类
	*conn链接资源
	*
	*/
class conn{
	private $host='';
	private $user='';
	private $passWord='';
	private $dbName='';
	public  $result='';
	private $mysqli='';
	private $rowArray='';
	private $rowsArray=array();
    public  function __construct($host,$user,$passWord,$dbName){
		if($host!=''){
	       $this->host=$host;
		}
		if($user!=''){
		   $this->user=$user;
		}
		if($passWord!=''){
			$this->passWord=$passWord;
		}
		if($dbName!=''){
			$this->dbName=$dbName;
		}
		$this->conn();
	}
	private function conn(){
		@$this->mysqli = new mysqli($this->host,$this->user,$this->passWord,$this->dbName);

		if(mysqli_connect_error()!=''){
            echo '数据库链接失败！';
            exit();
        }else{
		    return true;
        }
		/*if (mysqli_connect_errno()) {
			return false;
			exit();
		}else{
			return  true;
		}*/
	}
	/*查询结果*/
	public function mysqli_query_rst($sqls){
		if($this->mysqli==''){
			$this->conn();
		}
		$this->result=$this->mysqli->query($sqls);
		if($this->mysqli->errno){
			return false;
		}else{
		return true;
		}
	}
	/*返回查询记录数函数*/
	public function mysqli_get_rows($sqls){
		 if(!$this->mysqli_query_rst($sqls)){
		 	return false;
		 }else{
		 	return $this->result->num_rows;
		 }
	}
	/*取的一条记录，将结果输出成一个数组并返回，该函数处理的是单条记录*/

	public function get_row_array($sqls){
		if($this->mysqli_query_rst($sqls)==false){
			return false;
		}else{
			$this->rowArray=$this->result->fetch_row();
			return $this->rowArray;
		}
	}
	/*将取到的结果输出成一个数组并返回，该函数处理的是多条记录*/
	public function get_rows_array($sqls){
		if($this->mysqli_query_rst($sqls)==false){
			return false;
		}else{
		while($rows=$this->result->fetch_array()){
			 $this->rowsArray[]=$rows;
		 }
			return $this->rowsArray;
		}
	}
	/*数据库的添加，删除，修改，并返回受影响行数*/
	public function aduRst($sqls){
	  if($this->mysqli_query_rst($sqls)==false){
		  return false;
	  }else{
		  return $this->mysqli->affected_rows; 
	  }
	}
	/*释放结果集在不在需要使用的是数据删除。释放内存*/
	public function close_rst(){
		if(!is_object($this->result)){
			return false;
		}else{
		$this->result->close();	
			return true;
		}
	}
	/*关闭数据库*/
	public function close_mysql(){
		if($this->mysqli!=''){
			$this->mysqli->close();
			return true;
		}else{
			return false;
		}
	}
}